package com.woniuxy.depot.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniuxy.depot.model.DTO.Condition;
import com.woniuxy.depot.model.DTO.InStockDTO;
import com.woniuxy.depot.model.DTO.Statistics;
import com.woniuxy.depot.model.VO.StockGoodsVO;
import com.woniuxy.depot.model.VO.StockGoodssVO;
import com.woniuxy.depot.model.entity.DepotInStock;
import com.woniuxy.depot.service.DepotInStockService;
import com.woniuxy.response.ResponseResult;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/inStock")
public class DepotInStockController {
    @Resource
    private DepotInStockService inStockService;
    @GetMapping("/all/{current}/{size}")
    public ResponseResult<Page<DepotInStock>> all(@PathVariable int current,@PathVariable int size){

        return new ResponseResult<>(ResponseResult.SUCCESS,"success",inStockService.all(current,size));
    }

    @GetMapping("/searchByGoodsCode")
    public ResponseResult<List<DepotInStock>> searchByGoodsCode(@RequestParam String code){
        return new ResponseResult<>(ResponseResult.SUCCESS,"success",inStockService.searchByGoodsCode(code));
    }

    @PostMapping("/searchByCondition")
    public ResponseResult<List<DepotInStock>> searchByCondition(@RequestBody Condition condition) {

        return new ResponseResult<>(ResponseResult.SUCCESS,"success",inStockService.searchByCondition(condition));
    }
    @PreAuthorize("hasAuthority('depot:agreeIn')")
    @PutMapping("/updateState/{formNo}/{state}")
    public ResponseResult<Boolean> updateState(@PathVariable String formNo,@PathVariable Integer state){

        return new ResponseResult<>(ResponseResult.SUCCESS,"success",inStockService.updateState(formNo,state));
    }

    @PreAuthorize("hasAuthority('depot:addIn')")
    @PostMapping("/insert")
    public ResponseResult<Boolean> insert(@RequestBody InStockDTO inStockDTO){
        return new ResponseResult<>(ResponseResult.SUCCESS,"success",inStockService.insert(inStockDTO));
    }

    @GetMapping("/detail/{id}")
    public ResponseResult<List<StockGoodssVO>> detail(@PathVariable Integer id){
        return new ResponseResult<>(ResponseResult.SUCCESS,"success",inStockService.detail(id));
    }

    @GetMapping("/statistics")
    public ResponseResult<List<Statistics>> statistics(){
        return new ResponseResult<>(ResponseResult.SUCCESS,"success",inStockService.statistics());
    }


}
